/**
* @file Sound.h
* @author Max Ocklind
* @version 2010-01-11
**/


#if !defined(SOUND_H)
#define SOUND_H


/* includes */

#include <vector>
#include <map>

#include "ALErrorChecker.h"
#include "SFXFilter.h"
#include "Timer.h"


/* defines */

#define NO_SOUND_SOURCE			  -1

// sound types
#define NORMAL_SOUND			  1

// defualt sound properties
#define DEFAULT_AL_LOOP			  AL_FALSE
#define DEFAULT_AL_PITCH		  1.0f
#define DEFAULT_AL_GAIN			  1.0f
#define DEFAULT_AL_ROLLOFF_FACTOR 1.0f


/* types */

typedef ALuint SoundBuffer;
typedef ALuint SoundSource;
typedef int    SoundType;


/* classes */

class Sound
{
protected:
	/**
	* A pointer to the Open AL error checking class.
	*/
	ALErrorChecker* errCheck;

	/**
	* An Open AL sound source used to play and modify the loaded sound.
	*/
	SoundSource mSource;

	/**
	* The sound priority, used to compare importance of sounds.
	*/
	int mPriority;

	/**
	* The distance culling type.
	*/
	const char* mCullType;

	/**
	* The sound type.
	*/
	SoundType mSoundType;

	/**
	* The pointers to a SFXFilter enabled on the source.
	*/
	SFXFilter* mSFXFilter;

	/**
	* The timer associated with the SFXFilter.
	*/
	Timer mSFXFilterTimer;


public:
	/**
	* The default constructor.
	*/
	Sound()
	{
		Sound(NO_SOUND_SOURCE);
	} /* Sound() */

	/**
	* A constructor setting the specified OpenAL sound source.
	*
	* @param source the OpenAL sound source to be used by this <code>Sound</code> object
	*/
	Sound(SoundSource source)
	{
		errCheck = ALErrorChecker::instancePtr();

		// set initial values
		reset(source);
	} /* Sound(SoundSource source) */
	

	/* functions */

	void		 setVolume(ALfloat gain);
	ALfloat		 getVolume();
	
	virtual void setProperties(ALfloat* position, ALfloat* velocity, ALboolean loop, ALfloat pitch, ALfloat gain, ALfloat rolloffFactor);
	void		 updatePositionAndVelocity(ALfloat* position, ALfloat* velocity);

	virtual void play(SoundBuffer buffer, int priority, const char* cullType, ALfloat* position, ALfloat* velocity);
	virtual void play(SoundBuffer buffer, int priority, const char* cullType, ALfloat* position, ALfloat* velocity, SFXFilter* filter, unsigned long timeLimit);
	virtual void play(SoundBuffer buffer, int priority, const char* cullType, ALfloat* position, ALfloat* velocity, ALboolean loop, ALfloat pitch, ALfloat gain, ALfloat rolloffFactor, SFXFilter* filter, unsigned long timeLimit);

	void		 play();
	void		 pause();
	void		 resume();
	void		 stop();

	bool		 isPlaying();
	bool		 isPaused();
	bool		 isStopped();

	ALint		 getState();
	int			 getPriority();
	SoundType	 getSoundType();
	const char*	 getCullType();
	SoundSource  getSoundSource();

	void		 enableSFXFilter(SFXFilter* filter, unsigned long timeLimit);
	void		 disableSFXFilter();
	SFXFilter*   hasSFXFilter();

	virtual void update();
	virtual void reset(SoundSource source);

}; /* Sound */

#endif /* SOUND_H */